<?php
if(!isset($_SESSION["username"]))
					{
						header('location:Login.php');
					}
?>
<div class="navbar">
    	<div class="navbar-inner">
       	  <div class="container">
            	<a class="brand" href="HomePageAdmin.php">Trang chủ</a>         
            <ul class="nav" >
           	  <li class="dropdown">
                    	<a href="#" class="dropdown-toggle" data-toggle="dropdown">Hệ thống <i class="caret"></i></a>
                    	<ul class="dropdown-menu">
                        	<li><a href="Account.php"><i class="icon-user"></i> Quản lý người dùng</a></li>
                            <li><a href="GroupRole.php"><i class="icon-list-alt"></i> Nhóm quyền</a></li>
                            <li><a href="Role.php"><i class="icon-ok"></i> Quyền</a></li>
                        </ul>
              </li>
              <li class="dropdown">
                    	<a href="#" class="dropdown-toggle" data-toggle="dropdown">Bài viết <i class="caret"></i></a>
                        <ul class="dropdown-menu">
                        	<li><a href="Topic.php" title="Chủ đề bài viết cũng là danh sách menu hiển thị trên trang người dùng"><i class="icon-star-empty"></i> Quản lý chủ đề (menu)</a></li>
                        	<li><a href="News.php"><i class="icon-book"></i> Quản lý bài viết</a></li>
                            <li><a href="WriteNews.php"><i class="icon-pencil"></i> Viết bài</a></li>
                        </ul>
              </li>
                    <li><a href="Advertisement.php">Quảng cáo</a></li>
                    <li><a href="Vote.php">Bình chọn</a></li>
                    <li><a href="#">Thống kê</a></li>
                    <li><a href="Feedback.php">Góp ý - Báo lỗi</a></li>                  
              </ul>
               
              <ul class="nav pull-right">
               	  <li class="divider-vertical"></li>
                  <li class="dropdown">
                   	  <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="caret"></i> <?php echo $_SESSION["username"]; ?> 
                      <img src="../Images/Img_User/<?php echo $_SESSION["avatar"]; ?>"  alt="image user" id="img_avatar_small" /> </a>
                   	  <ul class="dropdown-menu">
                       	  <li><a href="MyProfile.php"><i class="icon-folder-open"></i> Hồ sơ cá nhân</a></li>
                          <li><a href="#changepass" data-toggle="modal" onclick="Reset();"><i class=" icon-refresh"></i> Đổi mật khẩu</a></li>
                          <li class="divider"></li>
                          <li><a href="Login.php"><i class="icon-off"></i> Thoát</a></li>
                      </ul>
                  </li>
              </ul>
                 
            </div>      	
        </div>
       
    </div>
     <!---------------------------------Đổi mật khẩu--------------------------------------------->
        <div class="modal hide fade"  id="changepass">
            <div class="modal-header">
            <a class="close" data-dismiss="modal">×</a>
            <h3>Thay đổi mật khẩu</h3>
            </div>
            <div class="modal-body">
            <p>
                <form action="" method="get" id="formchangepass">
               <!-- <div class="alert alert-success hide" id="alertChangePass">
                        <a class="close" data-dismiss="alert" href="#">&times;</a>
                        <strong></strong>
                </div> -->
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                     	<tr>
                                <td>Mật khẩu cũ:</td>
                                <td><input name="txtPass" type="password" id="txtPass" class="validate[required,funcCall[checkSpLetter]]" /></td>
                              </tr>
                              <tr>
                                <td>Mật khẩu mới:</td>
                                <td><input name="txtNewPass" type="password" id="txtNewPass" class="validate[required,funcCall[checkSpLetter]]" /></td>
                              </tr>
                              <tr>
                                <td>Xác nhận lại:</td>
                                <td><input name="txtRePass" type="password" id="txtRePass" class="validate[required,equals[txtNewPass]]" /></td>
                              </tr>
                              <tr>
                              	<td></td>
                                <td>
                                	<a href="#" class="btn" data-dismiss="modal">Đóng lại</a>
            						<button type="submit" class="btn btn-primary" id="btnSave">Cập nhật</button>
                               	</td>
                          </tr>  
                    </table>
        
                </form>
               <script type="text/javascript">
               $(document).ready(function(){
						$("#formchangepass #btnSave").click(function(){
																	var user='<?php echo $_SESSION["username"]; ?>';
																	var oldpass=$('#txtPass').val();
																	var newpass=$('#txtNewPass').val();
																	var repass=$('#txtRePass').val();
									if(user!=''&& oldpass!=''&& newpass!=''&& repass==newpass && validText(oldpass))
									{
										
																	$.ajax({
																		 url:"process/Account_add.php",
																		 data:{task:"changepass",username:user, oldpass:oldpass, newpass:newpass},
																		 type:"post",
																		 dataType:"json",
																		 success:function(res)
																		 {
																			
																				 alert(res.msg);
																			 
																		 }
																		   });
																	return false;
									}
									return true;
																	 
																	 })					   
										   
				});
               </script>
            </p>
            </div>
            <div class="modal-footer">           
            </div>
        
        <script>
		$(function(){
				$("#formchangepass").validationEngine();
		});//close jquery
		/**
		*
		* @param {jqObject} the field where the validation applies
		* @param {Array[String]} validation rules for this field
		* @param {int} rule index
		* @param {Map} form options
		* @return an error string if validation failed
		*/
		function checkSpLetter(field, rules, i, options){
			if (validText(field.val())==false) {
				// this allows to use i18 for the error msgs
				return options.allrules.validate2Spletters.alertText;
			}
		}
		function validText(value) {
			var chaos = new Array ("'"," ","--","\"");
			var sum = chaos.length;
			for (var i in chaos) {if (!Array.prototype[i]) {sum += value.lastIndexOf(chaos[i])}}
			if (sum) {
			return false;
			}
			return true;
		}
		function Reset()
		{
			document.getElementById("txtPass").value="";
			document.getElementById("txtNewPass").value="";
			document.getElementById("txtRePass").value="";
		}
	</script>